$button-radius: 2px;
$button-padding-x: 14px;
$button-font-size: 14px;
$button-min-with: 100px;
$button-height: 30px;

$button-xl-padding-x: 22px;
$button-xl-font-size: 16px;
$button-xl-min-width: 160px;
$button-xl-height: 40px;

$button-lg-padding-x: 18px;
$button-lg-font-size: 16px;
$button-lg-min-width: 120px;
$button-lg-height: 36px;

$button-sm-padding-x: 12px;
$button-sm-font-size: 12px;
$button-sm-min-width: 86px;
$button-sm-height: 26px;

$button-xs-padding-x: 10px;
$button-xs-font-size: 12px;
$button-xs-min-width: 80px;
$button-xs-height: 24px;


// firefox 按钮激活后文字周边有虚线
button::-moz-focus-inner {
  border: 0;
}

.button {
  display: inline-block; // 支持 <a> 标签
  outline: 0;
  border: 1px solid transparent;
  text-align: center;
  user-select: none;
  cursor: pointer;
  vertical-align: middle;
  border-radius: $button-radius;

  @include button-size($button-padding-x, $button-height, $button-font-size, $button-min-with);

  @include colors($button-white-color, transparent, $primary-color);

  // hover和active都是加深 10%
  &:hover, &:active, &.button-active {
    @include colors($button-white-color, transparent, darken($primary-color, 10%));
  }

  &.button-disabled, &:disabled {
    // TODO: 颜色需要抽离到variables
    @include colors($button-white-color, transparent, $button-disabled-color);
    cursor: not-allowed;
  }
}

// 清除a标签的下划线
a.button:hover {
  text-decoration: none;
}

// 每个尺寸的按钮大小
.button-xl {
  @include button-size($button-xl-padding-x, $button-xl-height, $button-xl-font-size, $button-xl-min-width);
}

.button-lg {
  @include button-size($button-lg-padding-x, $button-lg-height, $button-lg-font-size, $button-lg-min-width);
}

.button-sm {
  @include button-size($button-sm-padding-x, $button-sm-height, $button-sm-font-size, $button-sm-min-width);
}

.button-xs {
  @include button-size($button-xs-padding-x, $button-xs-height, $button-xs-font-size, $button-xs-min-width);
}

// 长按钮
.button-long {
  width: 100%;
}

// 短按钮，没有min-width
.button-short {
  min-width: auto;
}

.button-fat {
  height: 100%;

  // 清除水平方向的margin,防止按钮错位
  margin-bottom: 0;
  margin-top: 0;

  // 上对齐，防止按钮错位
  vertical-align: top;
}

// 矩形按钮
.button-rectangle {
  border-radius: 0;
}

.button-round {
  border-radius: $button-xl-height / 2;
}

// 次要按钮
.button-secondary {
  @include colors($primary-color, $primary-color, $button-white-color);

  // hover和active都是加深 10%
  &:hover, &:active, &.button-active {
    @include colors($button-white-color, transparent, $primary-color);
  }

  ＆.button-disabled, &:disabled {
    @include colors($text-placeholder-color, $module-border-color, $button-white-color);
    cursor: not-allowed;
  }
}

// 每种颜色的按钮
@each $color, $value in $theme-colors {
  .button-#{$color} {
    @include colors($button-white-color, $value, $value);

    &.button-secondary {
      @include colors($value, $value, $button-white-color);
    }

    // hover和active都是加深 10%
    &:hover, &:active, &.button-active {
      @include colors($button-white-color, transparent, darken($value, 10%));
    }

    &.button-disabled, &:disabled {
      background-color: $button-disabled-color;
      border-color: $button-disabled-color;
      cursor: not-allowed;
    }
  }
}

// 边线按钮
.button-outline {
  @include colors($text-color, $border-color, $button-white-color);

  &:hover, &:active, &.button-active {
    @include colors($primary-color, $primary-color, $button-white-color);
  }

  &.button-disabled, &:disabled {
    @include colors($text-placeholder-color, $module-border-color, $button-white-color);
    cursor: not-allowed;
  }
}

// 虚线按钮
.button-dashed {
  @extend .button-outline;

  border-color: #a4a4a4;
  border-style: dashed;

  &.button-disabled, &:disabled {
    // TODO: 颜色需要抽离到variables
    @include colors($text-placeholder-color, #ddd, $button-white-color);
    cursor: not-allowed;
  }
}

// 文本按钮
.button-text {
  @include colors($link-color, transparent, $button-white-color);

  // 文本按钮不需要padding-left和padding-right
  padding-left: 0;
  padding-right: 0;

  // 取消最小宽度限制
  min-width: auto;

  &:hover, &:active, &.button-active {
    @include colors($primary-color, transparent, $button-white-color);
  }

  &.button-disabled, &:disabled {
    @include colors($text-placeholder-color, transparent, $button-white-color);
    cursor: not-allowed;
  }
}

// 修复实际项目中的兼容性bug
.button {
  // 覆盖 .panel-clue button { color: #262626 }
  &.button-primary {
    color: $button-white-color;
  }
}
